

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改题目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <input type="hidden" name="questionId" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;margin-right: 5px">*</span>题目类型</label>
        <div class="layui-input-inline">
            <select name="questionType" lay-verify="required">
                <option value="">--请选择--</option>
                <option value="0">判断题</option>
                <option value="1">单选题</option>
                <option value="2">多选题</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;margin-right: 5px">*</span>所属题库</label>
        <div class="layui-input-inline">
            <select name="bankId" lay-verify="required">
                <option value="">--请选择--</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;margin-right: 5px">*</span>题目内容</label>
        <div class="layui-input-inline">
            <textarea name="questionContent" lay-verify="required" style="width: 400px; height: 150px;" placeholder="请输入题目内容..." autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">答案解析</label>
        <div class="layui-input-inline">
            <textarea name="questionAnalysis" style="width: 400px; height: 150px;" placeholder="请输入题目内容..." autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;margin-right: 5px">*</span>题目答案</label>
        <div class="layui-input-inline">
            <input type="text" name="questionAnswer" lay-verify="required" placeholder="请输入题目答案..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;margin-right: 5px">*</span>选项A</label>
        <div class="layui-input-inline">
            <input type="text" name="optionA" style="width:400px;" lay-verify="required" placeholder="请输入选项内容..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;margin-right: 5px">*</span>选项B</label>
        <div class="layui-input-inline">
            <input type="text" name="optionB" style="width:400px;" lay-verify="required" placeholder="请输入选项内容..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选项C</label>
        <div class="layui-input-inline">
            <input type="text" name="optionC" style="width:400px;" placeholder="请输入选项内容..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选项D</label>
        <div class="layui-input-inline">
            <input type="text" name="optionD" style="width:400px;" placeholder="请输入选项内容..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选项E</label>
        <div class="layui-input-inline">
            <input type="text" name="optionE" style="width:400px;" placeholder="请输入选项内容..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选项F</label>
        <div class="layui-input-inline">
            <input type="text" name="optionF" style="width:400px;" placeholder="请输入选项内容..." autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$
            ,form = layui.form;
        initBankId($,form);
        //回显
        var editData = parent.editData;
        console.log(editData);
        $('[name=questionType] option').each(function (index,value) {
            if($(this).val() == editData.questionType){
                $(this).attr("selected",true);
            }
        });
        $('[name=bankId] option').each(function (index,value) {
            if($(this).val() == editData.bankId){
                $(this).attr("selected",true);
            }
        });
        $('[name=questionId]').val(editData.questionId);
        $('[name=questionContent]').val(editData.questionContent);
        $('[name=questionAnalysis]').val(editData.questionAnalysis);
        $('[name=questionAnswer]').val(editData.questionAnswer);
        $('[name=optionA]').val(editData.optionA);
        $('[name=optionB]').val(editData.optionB);
        $('[name=optionC]').val(editData.optionC);
        $('[name=optionD]').val(editData.optionD);
        $('[name=optionE]').val(editData.optionE);
        $('[name=optionF]').val(editData.optionF);
        form.render();

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            console.log(field);

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.ajax({
                url:"/admin/question/question",
                method:"put",
                data:field,
                dataType:"json",
                async:false,
                success:function(obj){
                    if(obj.code == 0){
                        parent.layui.table.reload('table-question'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    }else{
                        layer.msg(obj.msg);
                    }
                }
            });
        });
    })

    function initBankId($,form){
        $.ajax({
            url:"/admin/questionBank/expertBanks",
            method:"get",
            dataType:"json",
            async:false,
            success:function(data){
                var html = '';
                for(var i in data){
                    html +='<option value='+data[i].bankId+'>'+data[i].bankName+'</option>';
                }
                $('select[name=bankId]').append(html);
                form.render();
            }
        });
    }
</script>
</body>
</html>